local iodatas = require("core_kukude/data/insertobjs")

AddPrefabPostInit("kukude", function(inst)
    if not TheWorld.ismastersim then return end

    inst.components.kkd_dissect:SetOnDissectFn("unlock_recipe", function(inst, target)
        for prefab, data in pairs(iodatas) do
            local unlock = data.unlock
            local tar_prefab = target.prefab
            local should_unlock = false
            if type(unlock) == 'string' then
                should_unlock = unlock == tar_prefab
            elseif type(unlock) == 'table' then
                for _, v in ipairs(unlock) do
                    if v == tar_prefab then
                        should_unlock = true
                        break
                    end
                end
            elseif type(unlock) == 'function' then
                should_unlock = unlock(target)
            end
            if should_unlock then
                if not inst.components.builder:KnowsRecipe(prefab) then
                    -- local recipe = GetValidRecipe(prefab)
                    inst.components.builder:UnlockRecipe(prefab)
                    inst:PushEvent("learnrecipe", { teacher = inst, recipe = prefab })  -- 雨：这里不要推配方，推prefab就行，应该是去获取图片的
                end
            end
        end
    end)
end)